﻿//------------------------------------------------------------------------------
// System Name:   Customer Service Platform
// Component:     
// Created By:    
// Created Date:  2011-2-27
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASBCC.Business
{
    /// <summary>
    /// Base class for entity bound page
    /// </summary>
    public abstract class PagedPage : Page
    {


        protected abstract EntityDataSource EntitySource { get; }
      
        public int TotalRowCount
        {
            get
            {
                object obj2 = base.ViewState["EntityTotalRowCount"];
                return ((obj2 != null) ? ((int)obj2) : -1);
            }
            set
            {
                object obj2 = base.ViewState["EntityTotalRowCount"];
                if ((obj2 == null) || (((int)obj2) != value))
                {
                    base.ViewState["EntityTotalRowCount"] = value;
                }
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            EntitySource.Selected += EntitySource_Selected;
        }

        private void EntitySource_Selected(object sender, EntityDataSourceSelectedEventArgs e)
        {
            // get GridView: Total Records
            // http://bytes.com/topic/asp-net/answers/474887-gridview-total-records
            // 当EntityDataSource从ViewState加载时，e.TotalRowCount永远为-1，所以过滤掉
            if (e.TotalRowCount != -1)
                TotalRowCount = e.TotalRowCount;
        }


    }
}
